unit settingsForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, NumEdit, CommDlg, Dlgs, globals, subDomainUnit,
  ConstBufferUnit, TextureUnit, KernelUnit;

type
  TsettingsScreen = class(TForm)
    Panel1: TPanel;
    Panel3: TPanel;
    Label3: TLabel;
    Panel4: TPanel;
    Label1: TLabel;
    Panel5: TPanel;
    Label4: TLabel;
    Panel6: TPanel;
    Label5: TLabel;
    sdLabel1: TLabel;
    sdNameEdit: TEdit;
    sdLabel2: TLabel;
    sdLabel3: TLabel;
    sdLabel4: TLabel;
    sdLabel5: TLabel;
    cbLabel1: TLabel;
    cbNameEdit: TEdit;
    cbLabel2: TLabel;
    cbRegistersEdit: TIntEdit;
    cbLabel3: TLabel;
    cbTypeCombo: TComboBox;
    cbLabel4: TLabel;
    cbDataEdit: TEdit;
    txLabel1: TLabel;
    txnameEdit: TEdit;
    txLabel5: TLabel;
    txLODEdit: TIntEdit;
    txLabel6: TLabel;
    txFormatEdit: TEdit;
    txDimensionRadio: TRadioGroup;
    txLabel2: TLabel;
    txWidthEdit: TIntEdit;
    txLabel3: TLabel;
    txHeightEdit: TIntEdit;
    txLabel4: TLabel;
    txDepthEdit: TIntEdit;
    txLabel7: TLabel;
    txDataEdit: TEdit;
    Button1: TButton;
    Button2: TButton;
    SaveDialog1: TSaveDialog;
    Button3: TButton;
    sdXEdit: TFloatEdit;
    sdYEdit: TFloatEdit;
    sdHeightEdit: TFloatEdit;
    sdWidthEdit: TFloatEdit;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure sdNameEditKeyPress(Sender: TObject; var Key: Char);
    procedure sdXEditKeyPress(Sender: TObject; var Key: Char);
    procedure sdYEditKeyPress(Sender: TObject; var Key: Char);
    procedure sdWidthEditKeyPress(Sender: TObject; var Key: Char);
    procedure sdHeightEditKeyPress(Sender: TObject; var Key: Char);
    procedure cbNameEditKeyPress(Sender: TObject; var Key: Char);
    procedure cbRegistersEditKeyPress(Sender: TObject; var Key: Char);
    procedure cbDataEditKeyPress(Sender: TObject; var Key: Char);
    procedure txnameEditKeyPress(Sender: TObject; var Key: Char);
    procedure txWidthEditKeyPress(Sender: TObject; var Key: Char);
    procedure txHeightEditKeyPress(Sender: TObject; var Key: Char);
    procedure txDepthEditKeyPress(Sender: TObject; var Key: Char);
    procedure txLODEditKeyPress(Sender: TObject; var Key: Char);
    procedure txFormatEditKeyPress(Sender: TObject; var Key: Char);
    procedure txDataEditKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    openMode : Integer;
    f : TextFile;
    procedure clearGUI();
  public
    { Public declarations }
    procedure myShow(mode : Integer);
  end;

var
  settingsScreen: TsettingsScreen;


implementation

{$R *.dfm}

procedure TsettingsScreen.clearGUI();
begin
sdNameEdit.Text := '';
sdXEdit.Text := '';
sdYEdit.Text := '';
sdWidthEdit.Text := '';
sdHeightEdit.Text := '';
cbNameEdit.Text := '';
cbTypeCombo.ItemIndex := 0; //default
cbRegistersEdit.Text := '';
cbDataEdit.Text := '';
txnameEdit.Text := '';
txDimensionRadio.ItemIndex := 1; //default
txWidthEdit.Text := '';
txHeightEdit.Text := '';
txDepthEdit.Text := '';
txLODEdit.Text := '';
txFormatEdit.Text := '';
txDataEdit.Text := '';
end;

procedure TsettingsScreen.myShow(mode : Integer);
begin
openMode := mode;

// Clear the GUI
clearGUI();

// enable the required option (Subdomain, constBuffer, textures)
case openMode of
SUBDOMAIN_MODE:
                begin
                  Panel6.Enabled := true;
                  Panel4.Enabled := false;
                  Panel5.Enabled := false;
                  Panel6.Color := clNavy;
                  Panel5.Color := clGray;
                  Panel4.Color := clGray;
                  ActiveControl := sdNameEdit;
                end;
CONSTBUFFER_MODE:
                begin
                  Panel5.Enabled := true;
                  Panel4.Enabled := false;
                  Panel6.Enabled := false;
                  Panel5.Color := clNavy;
                  Panel4.Color := clGray;
                  Panel6.Color := clGray;
                  ActiveControl := cbNameEdit;
                end;
TEXTURE_MODE:
                begin
                  Panel4.Enabled := true;
                  Panel5.Enabled := false;
                  Panel6.Enabled := false;
                  Panel4.Color := clNavy;
                  Panel5.Color := clGray;
                  Panel6.Color := clGray;
                  ActiveControl := txnameEdit;
                end;
end;



showModal;
end;

procedure TsettingsScreen.Button2Click(Sender: TObject);
var
 i : Integer;
begin
SaveDialog1.FilterIndex := openMode - 1000;
if SaveDialog1.Execute then
   begin
      AssignFile(f, SaveDialog1.FileName);
      if not FileExists(SaveDialog1.FileName) then
         rewrite(f)
      else Append(f);
      case openMode of
      SUBDOMAIN_MODE:
                      begin
                        for i:=0 to sbDomainsList.Count-1 do
                          begin
                            Writeln(f, subDomainClass(sbDomainsList.Items[i]).get_Name());
                            Writeln(f, FloatToStr(subDomainClass(sbDomainsList.Items[i]).get_topLeft_X()));
                            Writeln(f, FloatToStr(subDomainClass(sbDomainsList.Items[i]).get_topLeft_Y()));
                            Writeln(f, FloatToStr(subDomainClass(sbDomainsList.Items[i]).get_width()));
                            Writeln(f, FloatToStr(subDomainClass(sbDomainsList.Items[i]).get_height()));
                            Writeln(f, '*****************************'); // seperator
                          end;
                        sbDomainsList.Clear;
                      end;
      CONSTBUFFER_MODE:
                      begin
                        for i:=0 to cBuffersList.Count-1 do
                          begin
                            Writeln(f, ConstBufferClass(cBuffersList.Items[i]).get_Name());
                            Writeln(f, ConstBufferClass(cBuffersList.Items[i]).get_Type());
                            Writeln(f, ConstBufferClass(cBuffersList.Items[i]).get_mNumregisters());
                            Writeln(f, ConstBufferClass(cBuffersList.Items[i]).get_data());
                            Writeln(f, '*****************************'); // seperator
                          end;
                        cBuffersList.Clear;
                      end;
      TEXTURE_MODE:
                      begin
                        for i:=0 to texturesList.Count-1 do
                          begin
                            Writeln(f, TextureClass(texturesList.Items[i]).get_Name());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_mDim());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_mNumLOD());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_width());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_height());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_depth());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_data());
                            Writeln(f, TextureClass(texturesList.Items[i]).get_mFormat());
                            Writeln(f, '*****************************'); // seperator
                          end;
                        texturesList.Clear;
                      end;
      end;
      CloseFile (f);
   end;
end;

procedure TsettingsScreen.Button1Click(Sender: TObject);
begin
close;
end;

procedure TsettingsScreen.Button3Click(Sender: TObject);
var
  sb : subDomainClass;
  cbuff : ConstBufferClass;
  tx : TextureClass;
begin
case openMode of
      SUBDOMAIN_MODE:
                      begin
                        sb := subDomainClass.Create(sdNameEdit.Text,
                              strToFloat(sdXEdit.Text),
                              strToFloat(sdYEdit.Text),
                              strToFloat(sdWidthEdit.Text),
                              strToFloat(sdHeightEdit.Text)
                             );
                        sbDomainsList.Add(sb);
                        ActiveControl := sdNameEdit;
                      end;
      CONSTBUFFER_MODE:
                      begin
                        cbuff := ConstBufferClass.Create(cbNameEdit.Text,
                                                         cbTypeCombo.Items.Strings[cbTypeCombo.ItemIndex],
                                                         strToInt(cbRegistersEdit.Text),
                                                         cbDataEdit.Text
                                                         );
                        cBuffersList.add(cbuff);
                        ActiveControl := cbNameEdit;
                      end;
      TEXTURE_MODE:
                      begin
                        tx := TextureClass.Create(txnameEdit.Text,
                                                  txDimensionRadio.ItemIndex,
                                                  strToInt(txLODEdit.Text),
                                                  strToInt(txWidthEdit.Text),
                                                  strToInt(txHeightEdit.Text),
                                                  strToInt(txDepthEdit.Text),
                                                  txDataEdit.Text,
                                                  txFormatEdit.Text
                                                  );
                        texturesList.add(tx);
                        ActiveControl := txnameEdit;
                      end;
      end;
clearGUI();
end;

procedure TsettingsScreen.sdNameEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := sdXEdit;
end;

procedure TsettingsScreen.sdXEditKeyPress(Sender: TObject; var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := sdYEdit;
end;

procedure TsettingsScreen.sdYEditKeyPress(Sender: TObject; var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := sdWidthEdit;
end;

procedure TsettingsScreen.sdWidthEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := sdHeightEdit;
end;

procedure TsettingsScreen.sdHeightEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  Button3Click(nil);
end;

procedure TsettingsScreen.cbNameEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := cbTypeCombo;
end;

procedure TsettingsScreen.cbRegistersEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := cbDataEdit;
end;

procedure TsettingsScreen.cbDataEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  Button3Click(nil);
end;

procedure TsettingsScreen.txnameEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := txDimensionRadio;
end;

procedure TsettingsScreen.txWidthEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := txHeightEdit;
end;

procedure TsettingsScreen.txHeightEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := txDepthEdit;
end;

procedure TsettingsScreen.txDepthEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := txLODEdit;
end;

procedure TsettingsScreen.txLODEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := txFormatEdit;
end;

procedure TsettingsScreen.txFormatEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  ActiveControl := txDataEdit;
end;

procedure TsettingsScreen.txDataEditKeyPress(Sender: TObject;
  var Key: Char);
begin
if Key = char(13) then // for enter
  Button3Click(nil);
end;

end.
